<html>
<head>
    <meta charset="UTF-8">
    <title>微有趣</title>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="assets/css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="assets/css/forget.css"/>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

    <script type="text/javascript">
     	function changeSize() {
            var propo = $(window).width() / 640;
            $('html').css('font-size', 40 * propo + 'px');
        }
        ;
        changeSize();
        $(window).resize(function () {
            changeSize();
        });
        var countdown = 60;
        function settime(obj) {
            if (countdown == 0) {
                obj.removeAttribute("disabled");
                obj.value = "重新获取";
                countdown = 60;
                $("#yzm_btn").html(obj.value);
                return;
            } else {
                obj.setAttribute("disabled", true);
                obj.value = "重新发送(" + countdown + ")";
                countdown--;
                $("#yzm_btn").html(obj.value);
            }
            setTimeout(function () {
                    settime(obj)
                }
                , 1000)
        }
        //判断手机是否输入正确
        function is_phone() {
            var phone = $("#phone").val();
            if (phone && /^1[3|4|5|8]\d{9}$/.test(phone)) {
                $("#phone-span").html("");
                return true;
            } else {
                $("#phone-span").html("请输入正确手机号");
                return false;
            }
        }
        //验证码是否输入正确
        function is_yzm() {
            var yzm = $("#yzm_value").val();
            if (yzm && /^[0-9]*$/.test(yzm) && yzm.length == 6) {
                $("#yzm-span").html("");
                return true;
            } else {
                $("#yzm-span").html("验证码格式有误");
                return;
            }
        }
        //验证密码
        function is_password() {
            var password = $("#pwd").val();
            if (password == "") {
                $('#pwd-span').html("密码不能为空");
                return;
            } else {
                $("#pwd-span").html("");
                return true;
            }
        }
       // 验证二次输入密码
        function is_repassword() {
            var password = $("#pwd").val();
            var repassword = $("#repwd").val();
            if (repassword != password || repassword == "") {
                $("#repwd-span").html("两次密码不一致");
                return;
            } else {
                $("#repwd-span").html("");
                return true;
            }
        }
        $(function () {
            //判断用户鼠标焦点
            $("#phone").blur(function () {
                is_phone();
            });
            $("#pwd").blur(function () {
                is_password();
            });
            $("#repwd").blur(function () {
                is_repassword();
            })
            $("#yzm_value").blur(function () {
                is_yzm();
            })
            //发送验证码
            $("#yzm_btn").click(function () {
            	
                var phone = $("#phone").val();
                var yzm_btn = this;
                if (is_phone()) {
                    $.get("forget.class.php", {phone: phone}, function (data) {
                        $("#phone-span,#yzm-span").html("");
                        if (data == 1) {
                            settime(yzm_btn);
                        } else if (data == 3) {
                            $("#yzm-span").html("请在60秒后再次获取验证码");
                        } else {
                            $("#yzm-span").html("请稍后重试!");
                        }
                    })
                }
            });

            //拦截提交
            $("#regs_submit").click(function (){
                    var yzm_value = $("#yzm_value").val();
                    var phone = $("#phone").val();
                    var password = $("#pwd").val();
//                    alert(phone + " " + password + " " + yzm_value + " " + tj_id);
                    if (is_phone() && is_yzm() && is_password() &&  is_repassword()) {
                        setTimeout(function () {
                            $.post('forget.class.php', {
                                yzm_value: yzm_value,
                                phone: phone,
                                password: password
                            }, function (data) {
//                                alert(data);
                                $("#phone-span,#yzm-span").html("");
                                if (data == 1) {
                                    alert("修改成功");
                                    window.jsObj.readyGoLogin();
                                }else if (data == 0) {
                                    alert("验证信息有误");
                                }else {
                                    alert("修改失败");
                                }

                            })
                        }, 0)

                    }
                }
            )
        })
    </script>
</head>
<body>
<div class="wrap">
    <div class="con">
        <div class="one clearfix">
            <span class="icon1"></span><input id="phone" type="tel" placeholder="请输入手机号"/>
        </div>
        <span id="phone-span" class="ts"></span>
        <div class="two clearfix">
            <span class="icon2"></span><input id="yzm_value" type="text" placeholder="请输入验证码"/><button id="yzm_btn">获取验证码</button>
        </div>
        <span id="yzm-span" class="ts"></span>
        <div class="three clearfix">
            <span class="icon3"></span><input id="pwd" type="password" placeholder="请输入新密码"/>
        </div>
        <span id="pwd-span" class="ts"></span>
        <div class="four clearfix">
            <span class="icon3"></span><input id="repwd" type="password" placeholder="请再次输入密码"/>
        </div>
        <span id="repwd-span" class="ts"></span>
        <a class="btn" id="regs_submit">确定</a>
    </div>
</div>
</body>
</html>
